package edu.faytechcc.csc251.elementalTD;

import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;

/**
 * 10/10/2013 CIS 251
 *
 * Reads from file to build map and upperLevel of map
 *
 * @author William Robles
 */
public class LoadFile
{

    private int[][] mobInfo = new int[50][10];

    public void loadMap()
    {
        try
        {
            Scanner loadScanner = new Scanner(new File("load/map.alpha"));

            while (loadScanner.hasNext())
            {
                for (int y = 0;
                        y < GameDisplay.map.block.length;
                        y++)
                {
                    for (int x = 0;
                            x < GameDisplay.map.block[0].length;
                            x++)
                    {
                        GameDisplay.map.block[y][x].groundID = loadScanner.
                                nextInt();
                    }
                }
            }

            loadScanner.close();
        }
        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null,
                    "NO FILE DETECTED");
        }
    }

    public int[][] loadMobStat()
    {
        try
        {
            Scanner loadScanner = new Scanner(new File("load/mobInfo.csv"));
            String line;
            int level = 0;

            while (loadScanner.hasNext())
            {

                line = loadScanner.nextLine();
                if (!line.startsWith("#"))
                {
                    String[] array = line.split(",");
                    mobInfo[level][0] = Integer.parseInt(array[0]);
                    mobInfo[level][1] = Integer.parseInt(array[1]);
                    mobInfo[level][2] = Integer.parseInt(array[2]);
                    mobInfo[level][3] = Integer.parseInt(array[3]);
                    mobInfo[level][4] = Integer.parseInt(array[4]);
                    level++;
                }
            }

            loadScanner.close();
        }
        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null,
                    "NO FILE DETECTED");
        }

        return mobInfo;
    }
}
